package StrategyMode;

/**
 * 策略模式
 */
public class StrategyTest {
    //策略模式 是 通过传入不同的策略算法，来实现不同的结果
    public static void main(String[] args) {
        NormalZombie normalZombie = new NormalZombie(new StepByStep(), new BitAttack());
        normalZombie.display();
        normalZombie.move();
        normalZombie.attack();

        System.out.println("");

        FlagZombie flagZombie = new FlagZombie(new StepByStep(), new HitAttack());
        flagZombie.display();
        flagZombie.move();
        flagZombie.attack();
    }
}

//对于移动的抽象
interface Movable{
    void move();
}

//对于攻击的抽象
interface AttackAble{
    void attack();
}

abstract class Zombie{
    abstract public void display();
    Movable movable;
    AttackAble attackAble;

    abstract void move();
    abstract void attack();

    //使得继承该类的子类默认具有这两种方式
    public Zombie(Movable movable, AttackAble attackAble) {
        this.movable = movable;
        this.attackAble = attackAble;
    }

    public void setMovable(Movable movable) {
        this.movable = movable;
    }

    public void setAttackAble(AttackAble attackAble) {
        this.attackAble = attackAble;
    }

    public Movable getMovable() {
        return movable;
    }

    public AttackAble getAttackAble() {
        return attackAble;
    }
}


//对移动方式的具体实现
class StepByStep implements Movable{

    @Override
    public void move() {
        System.out.println("一步一步移动");
    }
}

//对攻击方式的具体实现1
class BitAttack implements AttackAble{

    @Override
    public void attack() {
        System.out.println("我的攻击方式是咬");
    }
}

//对攻击方式的具体实现2
class HitAttack implements AttackAble{

    @Override
    public void attack() {
        System.out.println("我的攻击方式是打");
    }
}

//普通僵尸
class NormalZombie extends Zombie{

    public NormalZombie() {
        super(new StepByStep(), new BitAttack());
    }

    public NormalZombie(Movable movable, AttackAble attackAble) {
        super(movable, attackAble);
    }

    @Override
    public void display() {
        System.out.println("我是普通僵尸");
    }

    @Override
    void move() {
        movable.move();
    }

    @Override
    void attack() {
        attackAble.attack();
    }
}

//摇旗僵尸
class FlagZombie extends Zombie{

    public FlagZombie() {
        super(new StepByStep(), new HitAttack());
    }

    public FlagZombie(Movable movable, AttackAble attackAble) {
        super(movable, attackAble);
    }

    @Override
    public void display() {
        System.out.println("我是摇旗僵尸");
    }

    @Override
    void move() {
        movable.move();
    }

    @Override
    void attack() {
        attackAble.attack();
    }
}
